<template>
  <div class="app-container">
    <el-row>
      <el-col :span="6">
<!--        <DatasourceMenu/>-->
        <div id="datasourceMenu">
          <el-menu
            default-active="2"
            class="datasourceMenu"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            @select="menuItemOpen"
            @open="menuOpen"
            :unique-opened="true"
          >
            <menu-node :menu="menu" parentIndex="-1" />
          </el-menu>
        </div>
      </el-col>
      <el-col :span="18">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="资源名称" prop="keyword">
            <el-input v-model="queryParams.keyword" placeholder="请输入资源名称" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="审核状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
              <el-option label="正常" :value="0" />
              <el-option label="保存" :value="-1" />
              <el-option label="未审核" :value="2" />
              <el-option label="未测试" :value="3" />
              <el-option label="下架" :value="1" />
              <el-option label="审核失败" :value="-2" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

<!--        <el-row :gutter="10" class="mb8">-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['datasourceBase:add']">注册</el-button>-->
<!--          </el-col>-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['datasourceBase:edit']">修改</el-button>-->
<!--          </el-col>-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['datasourceBase:remove']">删除</el-button>-->
<!--          </el-col>-->
<!--          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--        </el-row>-->

        <el-table v-loading="loading" :data="DatasourceBaseList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column type="index" width="50" align="center" label="序号"></el-table-column>
          <el-table-column label="资源名称" align="center" prop="resourceName" width="180" />
          <el-table-column label="对应数据通道" align="center" prop="resourceName" width="180" />

<!--          <el-table-column label="当前状态" align="center" prop="status">-->
<!--            <template slot-scope="scope">-->
<!--              <span v-if="scope.row.status == -2">审核失败</span>-->
<!--              <span v-else-if="scope.row.status == -1">保存</span>-->
<!--              <span v-else-if="scope.row.status == 0">正常(上架)</span>-->
<!--              <span v-else-if="scope.row.status == 1">下架</span>-->
<!--              <span v-else-if="scope.row.status == 2">未审核</span>-->
<!--              <span v-else-if="scope.row.status == 3">未测试</span>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="备注" align="center" prop="brief" :show-overflow-tooltip="true" />
          <!-- <el-table-column label="详细介绍" align="center" prop="detail"/> -->
          <el-table-column label="分类" align="center" prop="keyword" />
          <el-table-column label="所属用户" align="center" prop=""/>
          <el-table-column label="可见控制" align="center" prop="ownUserName">
            <template slot-scope="scope">
              <span>{{scope.row.ownUserName|| scope.row.createBy}}</span>
            </template>
          </el-table-column>
          <el-table-column label="所属单位" align="center" prop="unit" />
          <!-- <el-table-column label="接口配置ID" align="center" prop="id" /> -->
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-document" @click="handleSee(scope.row)">查看详情</el-button>
<!--              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['datasourceBase:edit']" v-if="scope.row.status=='0' ? false :true">修改</el-button>-->
<!--              <el-button size="mini" type="text" icon="el-icon-setting" @click="handleCheck(scope.row)" v-if="scope.row.status=='3' ? true : false">测试</el-button>-->
<!--              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['datasourceBase:remove']">删除</el-button>-->
<!--              <el-button size="mini" type="text" icon="el-icon-setting" @click="setSource(scope.row)" v-if="scope.row.status=='-1' ? true:false">配置</el-button>-->
<!--              <el-button size="mini" type="text" icon="el-icon-shopping-cart-2" @click="handleUp(scope.row)" v-if="(scope.row.status === 1 || scope.row.status === 0) ? true : false">{{ scope.row.status === 1 ? "上架" : "下架"}}</el-button>-->
            </template>
          </el-table-column>

        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
        <!-- 添加或修改数据资源信息信息对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
          <el-form ref="form" :model="form">
            <el-form label-width="100px" :rules="rules" :model='form'>
              <el-form-item label="资源名称" prop="resourceName">
                <el-input v-model="form.resourceName" placeholder="请输入资源名称" />
              </el-form-item>
              <el-form-item label="对应数据通道" prop="unit">
                <el-input v-model="form.unit" placeholder="请输入所属单位" />
              </el-form-item>
              <el-form-item label="所属分类" v-model="AllFieldTypeList">
                <el-checkbox-group v-model="form.typeIdList">
                  <el-checkbox v-for="(item, index) in AllFieldTypeList" :key="index" :label="item.id">{{item.fieldName}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="关键字" prop="keyword">
                <el-input v-model="form.keyword" placeholder="请填写关键词以 “ ; ”分号进行分割" />
              </el-form-item>
              <el-form-item label="备注" prop="brief">
                <el-input v-model="form.brief" placeholder="请输入数据通道简介" type="textarea" maxlength="255" show-word-limit />
              </el-form-item>

              <!-- <el-form-item label="展示图片" prop="iconUrl">
                <el-upload
                  class="upload-demo"
                  action=""
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :file-list="fileList"
                  list-type="picture"
                  v-model="form.iconUrl">
                  <el-button size="small" type="primary">点击上传</el-button>
                  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                </el-upload>
              </el-form-item> -->
            </el-form>
            <el-form :inline="true" v-model="form.datasourceDefaultControlList" label-width="80px">
              <div v-for="(item, index) in form.datasourceDefaultControlList" :key="index">
                <el-form-item label="特定用户" :prop="'datasourceDefaultControlList.' + index + '.userId'" style="width:11%">
                  <el-select placeholder="请选择" v-model="form.datasourceDefaultControlList[index].userId">
                    <el-option v-for="(item,index) in AllUserInfoList" :key="index" :label="item.nickName" :value="item.userId" />
                  </el-select>
                </el-form-item>
                <el-form-item label="用户类型" :prop="'datasourceDefaultControlList.' + index + '.userType'" style="width:11%">
                  <el-select v-model="item.userType" placeholder="请选择用户类型">
                    <el-option label="个人" :value="0" />
                    <el-option label="私人企业" :value="1" />
                    <el-option label="国有重点企业" :value="2" />
                    <el-option label="组织机构" :value="3" />
                    <el-option label="事业单位" :value="4" />
                    <el-option label="普通局委办" :value="5" />
                    <el-option label="权力机构" :value="6" />
                  </el-select>
                </el-form-item>
                <el-form-item label="用户级别" :prop="'datasourceDefaultControlList.' + index + '.userLevel'" style="width:11%">
                  <el-select v-model="item.userLevel" placeholder="请选择用户级别">
                    <el-option label="最低级用户" :value="0" />
                    <el-option label="低级用户" :value="1" />
                    <el-option label="中级用户" :value="2" />
                    <el-option label="高级用户" :value="3" />
                    <el-option label="最高级用户" :value="4" />
                  </el-select>
                </el-form-item>
                <el-form-item label="说明" :prop="'datasourceDefaultControlList.' + index + '.remark'" style="width:11%">
                  <el-input v-model="item.remark" placeholder="说明" type="text" />
                </el-form-item>
                <el-form-item label="用户访问" :prop="'datasourceDefaultControlList.' + index + '.isVisible'" style="width:11%">
                  <el-select v-model="item.isVisible" placeholder="请选择">
                    <el-option label="查询可见" :value="0" />
                    <el-option label="查询不可见" :value="1" />
                  </el-select>
                </el-form-item>
                <el-form-item label="共享模式" :prop="'datasourceDefaultControlList.' + index + '.sharedType'" style="width:11%">
                  <el-select v-model="item.sharedType" placeholder="请选择">
                    <el-option label="无条件共享" :value="0" />
                    <el-option label="有条件共享" :value="1" />
                  </el-select>
                </el-form-item>
                <el-form-item label="数据确权" :prop="'datasourceDefaultControlList.' + index + '.dataEnsureRightType'" style="width:11%">
                  <el-select v-model="item.dataEnsureRightType" placeholder="请选择">
                    <el-option label="不需要确权" :value="0" />
                    <el-option label="需要确权" :value="1" />
                  </el-select>
                </el-form-item>
                <el-form-item label="自由使用" :prop="'datasourceDefaultControlList.' + index + '.dataFreedomType'" style="width:11%">
                  <el-select v-model="item.dataFreedomType" placeholder="请选择">
                    <el-option label="不能生成用户自由使用的数据 " :value="0" />
                    <el-option label="可生成用户自由使用的数据" :value="1" />
                  </el-select>
                </el-form-item>
                <el-form-item style="width:40px">
                  <i class="el-icon-circle-plus" @click="addControlList()" style="font-size:20px;margin-right:10px"></i>
                  <i class="el-icon-remove" @click="deleteControlList(item, index)" style="font-size:20px"></i>
                </el-form-item>
              </div>
            </el-form>
            <!-- <el-button @click="addControlList" type="primary">增加</el-button> -->
<!--            <h3>默认设置&#45;&#45;默认价格设置</h3>-->

<!--            <el-form :inline="true" v-model="form.datasourceDefaultPriceList" label-width="80px">-->
<!--              <div v-for="(item, index) in form.datasourceDefaultPriceList" :key="index">-->
<!--                <el-form-item label="特定用户" :prop="'datasourceDefaultPriceList.' + index + '.userId'" style="width:11%">-->
<!--                  <el-select placeholder="请选择" v-model="form.datasourceDefaultPriceList[index].userId">-->
<!--                    <el-option v-for="(item,index) in AllUserInfoList" :key="index" :label="item.nickName" :value="item.userId" />-->
<!--                  </el-select>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="用户类型" :prop="'datasourceDefaultPriceList.' + index + '.userType'" style="width:11%">-->
<!--                  <el-select v-model="item.userType" placeholder="请选择用户类型">-->
<!--                    <el-option label="个人" :value="0" />-->
<!--                    <el-option label="私人企业" :value="1" />-->
<!--                    <el-option label="国有重点企业" :value="2" />-->
<!--                    <el-option label="组织机构" :value="3" />-->
<!--                    <el-option label="事业单位" :value="4" />-->
<!--                    <el-option label="普通局委办" :value="5" />-->
<!--                    <el-option label="权力机构" :value="6" />-->
<!--                  </el-select>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="用户级别" :prop="'datasourceDefaultPriceList.' + index + '.userLevel'" style="width:11%">-->
<!--                  <el-select v-model="item.userLevel" placeholder="请选择用户级别">-->
<!--                    <el-option label="最低级用户" :value="0" />-->
<!--                    <el-option label="低级用户" :value="1" />-->
<!--                    <el-option label="中级用户" :value="2" />-->
<!--                    <el-option label="高级用户" :value="3" />-->
<!--                    <el-option label="最高级用户" :value="4" />-->
<!--                  </el-select>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="计费类别" :prop="'datasourceDefaultPriceList.' + index + '.billingType'" style="width:11%">-->
<!--                  <el-select v-model="item.billingType" placeholder="请选择计费类别">-->
<!--                    <el-option label="按次数" :value="0" />-->
<!--                    <el-option label="按记录数" :value="2" />-->
<!--                    <el-option label="按字节" :value="3" />-->
<!--                    <el-option label="按时长" :value="4" />-->
<!--                  </el-select>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="使用周期" :prop="'datasourceDefaultPriceList.' + index + '.usePeriod'" style="width:11%" v-model="item.billingType">-->
<!--                  <el-input v-model="item.usePeriod" placeholder="使用周期">-->
<!--                    &lt;!&ndash; <template >-->
<!--                      <span v-if="item.billingType == 0" slot="suffix">次</span>-->
<!--                      <span v-else-if="item.billingType == 1" slot="suffix">条</span>-->
<!--                      <span v-else-if="item.billingType == 2" slot="suffix">KB</span>-->
<!--                      <span v-else-if="item.billingType == 3" slot="suffix">天</span>-->
<!--                    </template> &ndash;&gt;-->
<!--                  </el-input>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="计价单位" :prop="'datasourceDefaultPriceList.' + index + '.productUnit'" style="width:11%">-->
<!--                  <el-input v-model="item.productUnit" placeholder="请输入单位" />-->
<!--                </el-form-item>-->
<!--                <el-form-item label="价格" :prop="'datasourceDefaultPriceList.' + index + '.price'" style="width:11%">-->
<!--                  <el-input v-model="item.price" placeholder="请输入价格" />-->
<!--                </el-form-item>-->
<!--                <el-form-item label="补充说明" :prop="'datasourceDefaultPriceList.' + index + '.remark'" style="width:11%">-->
<!--                  <el-input v-model="item.remark" placeholder="补充说明" />-->
<!--                </el-form-item>-->
<!--                <el-form-item style="width:40px">-->
<!--                  <i class="el-icon-circle-plus" @click="addPriceList()" style="font-size:20px;margin-right:10px"></i>-->
<!--                  <i class="el-icon-remove" @click="deletePriceList(item, index)" style="font-size:20px;"></i>-->
<!--                </el-form-item>-->
<!--              </div>-->
<!--            </el-form>-->
<!--            &lt;!&ndash; <el-button @click="addPriceList" type="primary">增加</el-button> &ndash;&gt;-->
<!--            <h3>接口信息</h3>-->
<!--            <el-form v-if="form.datasourceInterface" v-model="form.datasourceInterface" label-width="100px">-->
<!--              <el-form-item label="数据通道" prop="sourceTypes">-->
<!--                <el-select v-model="form.datasourceInterface.sourceTypes" placeholder="请选择适用数据通道种类" style="width:100%">-->
<!--                  <el-option label="结构化" :value="0" />-->
<!--                  <el-option label="非结构化" :value="1" />-->
<!--                  <el-option label="实时" :value="2" />-->
<!--                  <el-option label="API" :value="3" />-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="具体类别" prop="sourceCategory">-->
<!--                <el-select v-model="form.datasourceInterface.sourceCategory" placeholder="请选择数据通道具体类别" style="width:100%">-->
<!--                  <el-option label="mysql" :value="0" />-->
<!--                  <el-option label="oracle" :value="1" />-->
<!--                  <el-option label="MongoDB" :value="2" />-->
<!--                  <el-option label="BigTable" :value="3" />-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="是否代理源" prop="isAgent">-->
<!--                <el-select v-model="form.datasourceInterface.isAgent" placeholder="请选择" style="width:100%">-->
<!--                  <el-option label="是" :value="0" />-->
<!--                  <el-option label="否" :value="1" />-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--              <el-row>-->
<!--                <el-col :span="12">-->
<!--                  <el-form-item label="引擎信息操作系统" prop="engineId">-->
<!--                    <el-select placeholder="请选择" v-model="form.datasourceInterface.engineId" @change="selectOrderId">-->
<!--                      <el-option v-for="(item,index) in AllEngineInfoList" :key="index" :label="item.system" :value="item.id" />-->
<!--                    </el-select>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="12">-->
<!--                  <el-form-item label="名字及版本操作适应系" prop="version">-->
<!--                    <div class="systemID">-->
<!--                      <el-input v-model="form.datasourceInterface.version" disabled name></el-input>-->
<!--                    </div>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
<!--              <el-row>-->
<!--                <el-col :span="12">-->
<!--                  <el-form-item label="获取授权码" prop="authCode">-->
<!--                    <el-button placeholder="" @click="getCode">点击获取</el-button>-->
<!--                    <el-input v-model="form.datasourceInterface.authCode" placeholder="" disabled name>-->
<!--                    </el-input>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="12">-->
<!--                  <el-form-item label="" prop="url">-->
<!--                    <div class="systemID">-->
<!--                      <el-button v-model="form.datasourceInterface.url" placeholder="" disabled name>引擎程序下载地址</el-button>-->
<!--                      <el-input v-model="form.datasourceInterface.url" placeholder="" disabled name></el-input>-->
<!--                    </div>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
<!--              <el-form-item label="数据库别名" prop="databaseAlias">-->
<!--                <el-input v-model="form.datasourceInterface.databaseAlias" placeholder="请录入数据库别名" />-->
<!--              </el-form-item>-->
<!--              <el-form-item label="数据库名称" prop="databaseName">-->
<!--                <el-input v-model="form.datasourceInterface.databaseName" placeholder="请录入数据库名称" />-->
<!--              </el-form-item>-->
<!--              <el-form-item label="登录用户名" prop="userName">-->
<!--                <el-input v-model="form.datasourceInterface.userName" placeholder="请录入登录用户名" />-->
<!--              </el-form-item>-->
<!--              <el-form-item label="登陆密码" prop="password">-->
<!--                <el-input v-model="form.datasourceInterface.password" placeholder="请录入登陆密码" />-->
<!--              </el-form-item>-->
<!--              <el-form-item label="地址" prop="ipaddress">-->
<!--                <el-input v-model="form.datasourceInterface.ipaddress" placeholder="请录入地址" />-->
<!--              </el-form-item>-->
<!--              <el-form-item label="端口" prop="port">-->
<!--                <el-input v-model="form.datasourceInterface.port" placeholder="请录入端口" />-->
<!--              </el-form-item>-->
<!--            </el-form>-->
            <!-- <el-form-item> -->
            <!-- <h3>结构信息</h3>
            </el-form-item>
            <el-form :inline="true" v-model="form.datasourceStructList" label-width="100px">
              <div v-for="(item, index) in form.datasourceStructList" :key="index">
                <el-form-item label="数据库表别名" :prop="'datasourceStructList.' + index + '.classAlias'" style="width:15%">
                  <el-input v-model="item.classAlias" placeholder="姓名" />
                </el-form-item>
                <el-form-item label="数据库表名" :prop="'datasourceStructList.' + index + '.representation'" style="width:15%">
                  <el-input v-model="item.representation" placeholder="人员信息" />
                </el-form-item>
                <el-form-item label="备注说明" :prop="'datasourceStructList.' + index + '.remark'" style="width:15%">
                  <el-input v-model="item.remark" placeholder="255字符" />
                </el-form-item>
                <el-form-item style="width:40px">
                  <i class="el-icon-circle-plus" @click="addStructList()" style="font-size:20px;margin-right:10px"></i>
                  <i class="el-icon-remove" @click="deleteStructList(item, index)" style="font-size:20px"></i>
                </el-form-item>
              </div>
            </el-form> -->
            <!-- <el-form v-if="form.datasourceStruct" v-model="form.datasourceStruct" label-width="100px" :inline="true">
              <el-form-item label="资源结构名称" prop="classAlias">
                <el-input v-model="form.datasourceStruct.classAlias" placeholder="请输入资源结构名称" />
              </el-form-item>
              <el-form-item label="资源结构表示" prop="representation">
                <el-input v-model="form.datasourceStruct.representation" placeholder="请输入资源结构表示" />
              </el-form-item>
              <el-form-item label="描述说明" prop="remark">
                <el-input v-model="form.datasourceStruct.remark" placeholder="请输入描述说明" />
              </el-form-item>
            </el-form> -->
            <!-- <el-form-item> -->
            <!-- <h3>资源内容</h3> -->
            <!-- </el-form-item> -->
            <!-- <el-form-item label="对应表名称" :prop="dataStructId" style="width:50%">
                <el-select v-model="dataStructId" placeholder="请选择">
                  <el-option v-for="(item,index) in form.datasourceStructList" :key="index" :label="item.classAlias" :value="item.classAlias"></el-option>
                </el-select>
              </el-form-item> -->
            <!-- <el-form :inline="true" v-model="datasourceContentList" label-width="100px">
              <div v-for="(item, index) in datasourceContentList" :key="index">
                <el-form-item label="对应表名称" :prop="'datasourceContentList.' + index + '.dataStructId'" style="display:none">
                    <el-select v-model="dataStructId" placeholder="请选择">
                      <el-option v-for="(item,index) in form.datasourceStructList" :key="index" :label="item.classAlias" :value="item.classAlias"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="资源名称" :prop="'datasourceContentList.' + index + '.name'" :rules="{}" style="width:15%">
                  <el-input v-model="item.name" placeholder="姓名" />
                </el-form-item>
                <el-form-item label="对应结构" :prop="'datasourceContentList.' + index + '.tableName'" :rules="{}" style="width:15%">
                  <el-input v-model="item.tableName" placeholder="人员信息" />
                </el-form-item>
                <el-form-item label="具体资源" :prop="'datasourceContentList.' + index + '.columnName'" :rules="{}" style="width:15%">
                  <el-input v-model="item.columnName" placeholder="name" />
                </el-form-item>
                <el-form-item label="数据类型" :prop="'datasourceContentList.' + index + '.dataType'" :rules="{}" style="width:15%">
                  <el-select v-model="item.dataType" placeholder="请选择">
                    <el-option label="整数" :value="0" />
                    <el-option label="长整数" :value="1" />
                    <el-option label="字节" :value="2" />
                    <el-option label="浮点数" :value="3" />
                    <el-option label="时间" :value="4" />
                    <el-option label="字符串" :value="5" />
                  </el-select>
                </el-form-item>
                <el-form-item label="备注说明" :prop="'datasourceContentList.' + index + '.remark'" :rules="{}" style="width:15%">
                  <el-input v-model="item.remark" placeholder="255字符" />
                </el-form-item>
                <el-form-item label="访问控制" :prop="'datasourceContentList.' + index + '.status'" style="width:12%">
                  <el-select v-model="item.status" placeholder="请选择">
                    <el-option label="编辑" :value="0" />
                    <el-option label="查看" :value="1" />
                  </el-select>
                </el-form-item>
                <el-form-item style="width:40px">
                  <i class="el-icon-circle-plus" @click="addContentList()" style="font-size:20px;margin-right:10px"></i>
                  <i class="el-icon-remove" @click="deleteContentList(item, index)" style="font-size:20px"></i>
                </el-form-item>
              </div>
            </el-form> -->
          </el-form>

          <div slot="footer" class="dialog-footer" prop="status">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button type="success" @click="temporarily">暂 存</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
        <!-- 查看详情对话框 -->
        <el-dialog :title="title1" :visible.sync="See1" width="1300px" append-to-body>
          <el-form ref="form" :model="form">
            <el-form label-width="85px">
              <el-col :span="12">
                <el-form-item label="资源名称：">{{ form.resourceName }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="对应数据通道">{{ form.unit }}</el-form-item>
              </el-col>
              <!-- v-for="(item,index) in form.typeIdList" :key="index" -->
              <el-col :span="24">
                <el-form-item label="所在表名">{{ form.detail }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="所属分类："><span v-for="(item,index) in form.fieldTypeList" :key="index"> {{ item.fieldName }} &nbsp;&nbsp;</span></el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="关键词：">{{ form.keyword }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="备注">{{ form.brief }}</el-form-item>
              </el-col>
              <el-form-item label="具体信息">
                <el-table>
                  <el-table-column label="name"></el-table-column>
                  <el-table-column label="alias"></el-table-column>
                  <el-table-column label="type"></el-table-column>
                </el-table>
              </el-form-item>
            </el-form>
            <br>
            <h3 style="font-weight:bolder;text-align:center">默认控制信息</h3>
            <el-form label-width="85px">
              <div v-for="(item,index) in form.datasourceDefaultControlList" :key="index">
                <el-col :span="6">
                  <el-form-item label="特定用户：" :prop="'datasourceDefaultControlList.' + index + '.userId'">
                <span v-for="(item1,index1) in AllUserInfoList" :key="index1">
                  <span v-if="item1.userId==item.userId">
                    {{item1.nickName}}
                  </span>
                </span>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="用户类型：" :prop="'datasourceDefaultControlList.' + index + '.userType'">
                    {{ userType[item.userType] }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="用户级别：" :prop="'datasourceDefaultControlList.' + index + '.userLevel'">
                    {{ userLevel[item.userLevel] }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="指定用户：" :prop="'datasourceDefaultControlList.' + index + '.isVisible'">
                    {{ isVisible[item.isVisible] }}
                  </el-form-item>
                </el-col>
              </div>
            </el-form>

          </el-form>
          <div slot="footer" class="dialog-footer" prop="status">
            <el-button type="primary" @click="See1 = false">确 定</el-button>
          </div>
        </el-dialog>
        <!-- 数据通道配置 -->
<!--        <el-dialog :title="title2" :visible.sync="See2" width="1200px" append-to-body>-->
<!--          <el-form ref="form" :model="form" label-width="120px">-->
<!--            <el-form-item label="配置资源ID" prop="radio">-->
<!--              <el-input v-model="infoId" disabled="disabled"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="配置资源方式" prop="radio">-->
<!--              <el-radio-group v-model="radio">-->
<!--                <el-radio v-model="radio" :label="1" :disabled="disabled">全人工</el-radio>-->
<!--                <el-radio v-model="radio" :label="2" :disabled="disabled">半自动</el-radio>-->
<!--                <el-radio v-model="radio" :label="3" :disabled="disabled">全自动</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
<!--            <el-upload class="upload-demo" v-if="radio==2" ref="resouceFile" :auto-upload="false" name="file" :on-change="handleUploadChange">-->
<!--              <el-form-item label="资源文件" style="margin-bottom:0px">-->
<!--                <el-button size="small" type="primary">选择资源文件</el-button>-->
<!--              </el-form-item>-->
<!--            </el-upload>-->
<!--            <el-upload class="upload-demo" v-if="radio==2||radio==3" ref="ruleFile" :auto-upload="false" name="rule" :on-change="handleUploadChange2">-->
<!--              <el-form-item label="规则文件" style="margin-bottom:0px">-->
<!--                <el-button size="small" type="primary">选择规则文件</el-button>-->
<!--              </el-form-item>-->
<!--            </el-upload>-->
<!--            <el-form-item label="上传文件" v-if="radio==2||radio==3">-->
<!--              <el-button size="small" type="primary"  @click="submitUpload">上传文件</el-button>-->
<!--            </el-form-item>-->
<!--            <div>-->
<!--              <el-table :data="AllDatasourceBaseStructList" border style="width:1160px">-->
<!--                <el-table-column type="index" width="50px" align="center" label="序号"></el-table-column>-->
<!--                <el-table-column prop="classAlias" label="数据库表别名" width="203px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.classAlias" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column prop="representation" label="数据库表名" width="203px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.representation" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column prop="keyword" label="表关键字" width="203px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.keyword" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column prop="remark" label="备注说明" width="298px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.remark" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column :render-header="renderHeader" width="202px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-button @click="delStructList(scope.row)" type="text" size="small">删除</el-button>-->
<!--                    <el-button type="text" size="small" @click="handelSave(scope.row)">保存</el-button>-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--              </el-table>-->
<!--              <pagination v-show="total1>0" :total="total1" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="setSource1" />-->

<!--              <br>-->
<!--              <el-form-item label="对应表名称" :prop="dataStructId" style="width:100%">-->
<!--                <el-select v-model="selectedValue" placeholder="请选择" @change="dian">-->
<!--                  <el-option v-for="(item,index) in AllDatasourceBaseStructList" :key="index" :label="item.classAlias" :value="item.id" @click="dian()"></el-option>-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--              &lt;!&ndash;  &ndash;&gt;-->
<!--              <el-table :data="tableData1" border style="width: 1160px">-->
<!--                <el-table-column type="index" width="50" align="center" label="序号"></el-table-column>-->
<!--                <el-table-column prop="name" label="资源名称" width="253px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.name" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column prop="columnName" label="对应结构" width="253px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.columnName" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                &lt;!&ndash; <el-table-column prop="dataType" label="数据类型" width="203px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-select v-model="scope.row.dataType" placeholder="请选择">-->
<!--                      <el-option label="整数" :value="'int'" />-->
<!--                      <el-option label="长整数" :value="'bigint'" />-->
<!--                      <el-option label="字节" :value="1" />-->
<!--                      <el-option label="浮点数" :value="'float'" />-->
<!--                      <el-option label="时间" :value="'datetime'" />-->
<!--                      <el-option label="字符串" :value="'varchar'" />-->
<!--                    </el-select>-->

<!--                  </template>-->
<!--                </el-table-column> &ndash;&gt;-->
<!--                <el-table-column prop="remark" label="备注说明" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-input v-model="scope.row.remark" style="width: 90%" />-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column :render-header="renderHeader1" width="253px" align="center">-->
<!--                  <template slot-scope="scope">-->
<!--                    <el-button @click="delStructList1(scope.row)" type="text" size="small">删除</el-button>-->
<!--                    <el-button type="text" size="small" @click="handelSave1(scope.row)">保存</el-button>-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--              </el-table>-->

<!--            </div>-->

<!--          </el-form>-->
<!--          <div slot="footer" class="dialog-footer" prop="status">-->
<!--            <el-button type="primary" @click="cancel2">关 闭</el-button>-->
<!--          </div>-->
<!--        </el-dialog>-->
      </el-col>
    </el-row>

  </div>
</template>

<script>

let id = 1000;
import axios from 'axios';
import {
  listDatasourceBase,
  getDatasourceBase,
  delDatasourceBase,
  addDatasourceBase,
  updateDatasourceBase,
  listAllDatasourceBase,
  operateDatasourceBase,
  checkDatasourceBase,
  getKeyword, menuDataSourceBase
} from '@/api/qysj/app/DatasourceBase.js'
import { listFieldType } from '@/api/qysj/app/FieldType'
import { listAllFieldType } from "@/api/qysj/app/FieldType.js";
import { listUser } from "@/api/system/user";
import { listAllEngineInfo } from "@/api/qysj/app/EngineInfo.js";
import { addEngineApply } from "@/api/qysj/app/EngineApply.js";
import{addDatasourceBaseStruct,delDatasourceBaseStruct,DatasourceBaseStructList,DatasourceBaseTaskInfo} from "@/api/qysj/app/datasourceBaseStruct.js";
import MenuNode from '@/views/qysj/data/source/MultiLevelMenu.vue'
export default {
  name: "DatasourceBase",
  components: { MenuNode },
  data() {
    const data = [{id: 1,label: "关键字:",},];
    return {
      data: JSON.parse(JSON.stringify(data)),
      disabled: false,
      options: [],
      fileList: [],
      radio: 1,
      show: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1:0,
      // 数据通道基本信息表格数据
      DatasourceBaseList: [],
      // 数据通道结构信息表格数据
      DatasourceStruct: [],
      // 数据通道接口表格数据
      // DatasourceInterface:
      // typeIdList: [],
      // 结构信息
      datasourceStructForm: [],
      // 结构信息提交表单
      // datasourceStructform:{},
      a:[],
      // 弹出层标题
      title: "",
      title1: "",
      title2: "",
      // 是否显示弹出层
      open: false,
      See1: false,
      See2: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createUserId: null,
        type: null,
        unit: null,
        status: null,
        brief: null,
        keyword: "",
        detail: null,
        resourceName: null,
        sourceId: null,
      },
      // queryParam1 :{
      //   pageNum: 1,
      //   pageSize: 5,
      //   sourceId: null,
      // },
      // 表单参数
      form: {},
      dataStructId: "",
      datasourceContentList: [
        {
          name: null,
          tableName: null,
          dataType: null,
          remark: null,
          sourceId: null,
        },
      ],
      // 表单校验
      rules: {
        unit: [
          { required: true, message: "所属单位不能为空", trigger: "blur" },
        ],
        resourceName: [
          { required: true, message: "资源名称不能为空", trigger: "blur" },
        ],
        brief: [{ required: true, message: "简介不能为空", trigger: "blur" }],
        detail: [
          { required: true, message: "详细介绍不能为空", trigger: "blur" },
        ],
        keyword: [
          {
            required: true,
            message: "请填写关键字且关键字之间以';'分隔",
            trigger: "blur",
          },
        ],
      },
      direction: "rtl",
      // 数据通道信息
      AllDatasourceBaseList: [],
      // 所属分类信息
      AllFieldTypeList: [],
      // 用户信息表
      AllUserInfoList: [],
      // 引擎信息表
      AllEngineInfoList: [],
      // 资源结构表
      AllDatasourceBaseStructList:[],
      // 关键字，列表
      keyList: [],
      // 用户类型
      userType: {
        0: "个人",
        1: "私人企业",
        2: "国有重点企业",
        3: "组织机构",
        4: "事业单位",
        5: "普通局委办",
        6: "权力机构",
      },
      userType1: {
        0: "个人",
        1: "私人企业",
        2: "国有重点企业",
        3: "组织机构",
        4: "事业单位",
        5: "普通局委办",
        6: "权力机构",
      },
      // 用户级别
      userLevel: {
        0: "最低级用户",
        1: "低级用户",
        2: "中级用户",
        3: "高级用户",
        4: "最高级用户",
      },
      userLevel1: {
        0: "最低级用户",
        1: "低级用户",
        2: "中级用户",
        3: "高级用户",
        4: "最高级用户",
      },
      // 共享模式
      shareType: {
        0: "无条件共享",
        1: "有条件共享",
      },
      //用户访问
      isVisible: {
        0: "查询可见",
        1: "查询不可见",
      },
      // 数据确权
      dataEnsureRightType: {
        0: "不需要确权",
        1: "需要确权",
      },
      // 自由使用
      dataFreedomType: {
        0: "不能生成用户自由使用的数据",
        1: "可生成用户自由使用的数据",
      },
      // 计费类别
      billingType: {
        0: "按次数",
        2: "按记录数",
        3: "按字节",
        4: "按时长",
      },
      // 数据通道种类
      sourceCategory: {
        0: "结构化",
        1: "非结构化",
        2: "实时",
        3: "API",
      },
      // 数据通道具体类别
      sourceTypes: {
        0: "mysql",
        1: "oracle",
        2: "MongDB",
        3: "BigTable",
      },
      // 是否代理源
      isAgent: {
        0: "是",
        1: "否",
      },
      // 数据类型
      dataType: {
        0: "整数",
        1: "长整数",
        2: "字节",
        3: "浮点数",
        4: "时间",
        5: "字符串",
      },
      // 访问控制
      status: {
        0: "编辑",
        1: "查看",
      },
      // 所属分类
      typeIdList: {
        1: "成都大学",
        2: "实验环境",
        3: "试运行环境",
        4: "气象数据",
        7: "畜牧业",
        8: "能源再回收",
        10: "1",
      },
      tableData: null,
      selectedValue: null,
      tableData1: [],
      selectSQltableId: null,
      currentDatasourceBaseStructList: [],
      uploadUrl: '/datasourceBase/analysis',
      infoId: null, // 上传时附带的信息ID
      loadIndex: '', // Loading组件的索引，用于关闭Loading
      analysisTimer: '', // 定时器，用于轮询查询解析状态
      resouceFile:null,//资源文件
      ruleFile:null,//规则文件
      // 目录查询参数
      MenuQueryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: null,
        type:0
      },
      menu:[],//目录数据
    };
  },
  created() {
    this.getList();
    this.setSource1();
    this.getMenuList()
  },

  methods: {
    menuItemOpen(key, keyPath) {
      console.log('item',key, keyPath);
      menuDataSourceBase({fieldTypeId:key}).then(res=>{
        this.AllDatasourceBaseList=res.data;
      })
      // const menu=require('@/api/menu.json')
      // console.log(menu.data)
    },
    menuOpen(index,indexPath){
      console.log('submenu',index,indexPath)
    },
    // 获取目录列表
    getMenuList(){
      listFieldType(this.queryParams).then(res=>{
        this.menu=res.rows;
        // console.log('menu',JSON.stringify(this.menu))
      })
    },
    /* 查询引擎信息信息列表 */
    getList() {
      this.loading = true;
      listDatasourceBase(this.queryParams).then((response) => {
        this.DatasourceBaseList = response.rows;
        // console.log(this.DatasourceBaseList)
        this.total = response.total;
        this.loading = false;
      });
      listAllDatasourceBase(this.queryParams).then((response) => {
        this.AllDatasourceBaseList = response.data;
      });
      listAllFieldType(this.queryParams).then((response) => {
        this.AllFieldTypeList = response.data;
      });
      listUser(this.queryParams).then((response) => {
        this.AllUserInfoList = response.rows;
      });
      listAllEngineInfo(this.queryParams).then((response) => {
        this.AllEngineInfoList = response.data;

      });
      getKeyword().then((response) => {
        this.keyList = response.data;
        // this.total = response.total;
        function bl(arr) {
          let newArr = [];
          arr.forEach((cc) => {
            let newa = {};
            newa.label = cc.sourceName;
            newa.value = cc.id;
            // console.log(cc.keywordList)
            let children = [];
            for (let i = 0; i < cc.keywordList.length; i++) {
              let child = {};
              child.label = cc.keywordList[i];
              child.value = cc.keywordList[i];
              children.push(child);
              newa.children = children;
            }
            newArr.push(newa);
          });

          return newArr;
        }
        this.options = bl(response.data);
        this.loading = false;
      });

    },
    selectOrderId() {
      const item = this.AllEngineInfoList.find(
        (item1) => item1.id === this.form.datasourceInterface.engineId
      );
      this.form.datasourceInterface.version = item.version;
      this.form.datasourceInterface.url = item.url;
    },
    //上传文件
    submitUpload(){
      // this.$refs.resouceFile.submit();
      // this.$refs.ruleFile.submit();
      if(this.radio == 2){//半自动
          let form = new FormData();
          form.append('file', this.resouceFile.raw);
          if(this.ruleFile){
            form.append('rule', this.ruleFile.raw);
          }
          form.append('sourceId', this.infoId);
          const config = {
            headers: { "Content-Type": "multipart/form-data;boundary="+new Date().getTime() }
          };
          axios.post('http://47.108.20.64:8082/prod-api/datasourceBase/analysis',form,config)
          .then(response => {
              this.handleUploadSuccess(response);
          })
      }else if(this.radio == 3){//全自动
          let form = new FormData();
          if(this.ruleFile){
            form.append('rule', this.ruleFile.raw);
          }
          form.append('sourceId', this.infoId);
          const config = {
            headers: { "Content-Type": "multipart/form-data;boundary="+new Date().getTime() }
          };
          axios.post('http://47.108.20.64:8082/prod-api/datasourceBase/automatic',form,config)
          .then(response => {
              this.handleUploadSuccess(response);
          })
      }

    },
    //上传前截取文件
    handleUploadChange(file, fileList){
      this.resouceFile = file;
    },
    handleUploadChange2(file, fileList){
      this.ruleFile = file;
    },
    // 解析上传的文件
    handleUploadSuccess(response) {
      if (response.code === 200) {
        // 显示Loading
        this.loadIndex = this.$loading({
          lock: true,
          text: '解析中，请稍候...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })

        // 开始轮询查询解析状态
        this.analysisTimer = setInterval(() => {
          this.queryDataStatus()
        }, 3000)
      } else {
        this.$message.error(response.msg)
      }
    },
    handleUploadError(error) {
      this.$message.error(error.message)
    },
    queryDataStatus() {
      // 查询解析状态的函数
      const params = { sourceId: this.infoId };
      DatasourceBaseTaskInfo(params).then(res => {
          if (res.code === 200) {
            if (res.data.execStatus === 2) {
              clearInterval(this.analysisTimer)
              this.analysisTimer = null
              this.$message.success('解析成功')
              DatasourceBaseStructList(this.queryParams).then((response) => {
                const result = response.rows;
                this.total1 = response.total
                this.AllDatasourceBaseStructList = result
              })
              this.loadIndex.close()
            } else if (res.data.execStatus === 3) {
              clearInterval(this.analysisTimer)
              this.analysisTimer = null
              this.$message.error('解析失败')
              this.loadIndex.close()
            } else if (res.data.execStatus === -1) {
              clearInterval(this.analysisTimer)
              this.analysisTimer = null
              this.$message.warning('已取消')
              this.loadIndex.close()
            }
          } else {
            clearInterval(this.analysisTimer)
            this.analysisTimer = null
            this.$message.error(res.msg)
            this.loadIndex.close()
          }
        })
      },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel1() {
      this.See1 = false;
      this.reset();
    },
    cancel2() {
      this.See2 = false;
      this.reset();
    },

    // 表单重置
    reset() {
        (this.dataStructId = ""),
        (this.datasourceContentList = [{name: null,tableName: null,dataType: null,remark: null,sourceId: null,},]),
        (this.form = {
          userId: null,brief: null,iconUrl: null,
          datasourceDefaultControlList: [
            {userId: null,userType: null,userLevel: null,sharedType: null,isVisible: null,remark: null,sourceId: null,dataEnsureRightType: null,dataFreedomType: null,},
          ],
          datasourceDefaultPriceList: [
            {userId: null,userType: null,userLevel: null,billingType: null,usePeriod: null,productUnit: null,price: null,remark: null,},
          ],
          datasourceInterface: {
            sourceTypes: null,sourceCategory: null,isAgent: null,databaseAlias: null,databaseName: null,userName: null,password: null,ipaddress: null,port: null,
            contentType: null,engineSerial: null,header: null,method: null,system: null,version: null,url: null,authCode: null,engineId: null,
          },
          detail: null,
          inputUserId: null,
          keyword: null,
          ownUserId: null,
          status: null,
          unit: null,
          defaultPwd: null,
          pwdSaveType: null,
          pwdType: null,
          datasourceContentList: [{name: null,tableName: null,dataType: null,remark: null,sourceId: null,},],
          datasourceStructList: [{classAlias: null,representation: null,remark: null,datasourceContentList: [],},],
          typeIdList: [],
        });
        this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "注册数据资源基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // console.log(row);
      this.open = true;
      this.title = "修改数据通道基本信息";
      let list = [];
      let name1 = [];
      const id = row.id || this.ids;
      getDatasourceBase(id).then((response) => {
        this.form = response.data;
        this.form.datasourceStructList.forEach(function (val, index) {
          if (val.datasourceContentList.length > 0) {
            list = val.datasourceContentList;
            name1 = val.classAlias;
          }
        });
        const item = this.AllEngineInfoList.find(
          (item1) => item1.id === this.form.datasourceInterface.engineId
        );
        // console.log(item)
        // this.form.datasourceInterface.system = item.system;
        // this.form.datasourceInterface.version = item.version;
        // this.form.datasourceInterface.url = item.url;
        this.datasourceContentList = list;
        this.dataStructId = name1;

      });
    },
    //上下架
    handleUp(row) {
      let data = {
        id: row.id,
        status: row.status === 0 ? -1 : 1,
      };
      operateDatasourceBase(data).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.getList();
      });
    },
    // 测试
    handleCheck(row) {
      let sourceId = row.id;
      if (row.status === 3) {
        this.show = true;
      }
      checkDatasourceBase(sourceId).then((response) => {
        this.$modal.msgSuccess("测试成功");
        this.getList();
      });
    },
    // 查看数据通道基本信息
    handleSee(row) {
      this.reset();
      let list = [];
      let name1 = [];
      const id = row.id || this.ids;
      getDatasourceBase(id).then((response) => {
        this.form = response.data;
        // this.form.datasourceStructList.forEach(function (val, index) {
        //   if (val.datasourceContentList.length > 0) {
        //     list = val.datasourceContentList;
        //     name1 = val.classAlias;
        //   }
        // });
        // this.datasourceContentList = list;
        this.dataStructId = name1;
        const item = this.AllEngineInfoList.find(
          (item1) => item1.id === this.form.datasourceInterface.engineId
        );
        // this.form.datasourceInterface.system = item.system;
        // this.form.datasourceInterface.version = item.version;
        // this.form.datasourceInterface.url = item.url;
        this.See1 = true;
        this.title1 = "数据通道基本信息";
      });
    },

    //暂存按钮
    temporarily() {
      let name1 = this.dataStructId;
      let list = this.datasourceContentList;
      this.$refs["form"].validate((valid) => {
        this.form.datasourceStructList.forEach(function (val, index) {
          if (val.classAlias == name1) {
            val.datasourceContentList = list;
          } else {
            val.datasourceContentList = [];
          }
        });
        this.form.status = -1;
        if (valid) {
          if (this.form.id) {
            updateDatasourceBase(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.inputUserId =
              this.form.inputUserId || sessionStorage.getItem("UserId");
            addDatasourceBase(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      let name1 = this.dataStructId;
      let list = this.datasourceContentList;
      this.$refs["form"].validate((valid) => {
        this.form.datasourceStructList.forEach(function (val, index) {
          if (val.classAlias == name1) {
            val.datasourceContentList = list;
          } else {
            val.datasourceContentList = [];
          }
        });
        this.form.status = 2;
        if (valid) {
          if (this.form.id) {
            updateDatasourceBase(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDatasourceBase(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 获取授权码
    getCode() {
      // console.log("ada",row);
      // let data = JSON.stringify({
      //   engineId: this.form.datasourceInterface.engineId,
      //   sourceId:this.form.id,
      // })
      let data = {
        engineId: this.form.datasourceInterface.engineId,
        sourceId: this.form.id,
      };
      addEngineApply(data).then((response) => {
        this.form.datasourceInterface.authCode = response.data.authCode;
        console.log(this.form.datasourceInterface.authCode);
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除id为"' + ids + '"的数据项？')
        .then(function () {
          return delDatasourceBase(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    // 配置
    setSource(row) {
       // 资源结构列表
      this.selectedValue = null;
      this.tableData1 = [];
      this.queryParams.sourceId = row.id;
      this.infoId = row.id;
       DatasourceBaseStructList(this.queryParams).then((response) => {
        const result = response.rows;
         this.total1 = response.total;
        this.AllDatasourceBaseStructList = result;
      })
      // this.AllDatasourceBaseStructList.forEach((val) => {
      //   if (val.sourceId == row.id) {
      //     console.log(val);
      //     this.DatasourceBaseStructList1 = val;
      //     console.log(this.DatasourceBaseStructList1);
      //   }
      // })
      this.a = row
      this.reset();
      this.See2 = true;
      this.title2 = "配置数据资源";
    },
    dian() {
      const selectedStruct = this.AllDatasourceBaseStructList.find(item => item.id == this.selectedValue);
      if (selectedStruct.id==this.selectedValue) {
        this.tableData1 = selectedStruct.datasourceContentList;
      } else {
        this.tableData1 = [];
      }


    },
    // 资源结构分页
    setSource1() {
      this.queryParams.sourceId = this.a.id;
      DatasourceBaseStructList(this.queryParams).then((response) => {
        this.AllDatasourceBaseStructList = response.rows;
        this.total1 = response.total;
      });
    },
    // 新增
    addControlList(index) {
      this.$refs["form"].validate((valid) => {
        // alert('submit!');
        this.form.datasourceDefaultControlList.push({
          ...this.form.datasourceDefaultControlList[index],
          userId: null,
          userType: null,
          userLevel: null,
          sharedType: null,
          isVisible: null,
          remark: null,
          dataFreedomType: null,
          dataEnsureRightType: null,
        });
      });
    },
    // 删除
    deleteControlList(item, index) {
      this.form.datasourceDefaultControlList.splice(index, 1);
    },
    addPriceList(index) {
      this.$refs["form"].validate((valid) => {
        // alert('submit!');
        this.form.datasourceDefaultPriceList.push({
          ...this.form.datasourceDefaultPriceList[index],
          userId: null,
          userType: null,
          userLevel: null,
          billingType: null,
          usePeriod: null,
          productUnit: null,
          price: null,
          remark: null,
        });
      });
    },

    // 删除
    deletePriceList(item, index) {
      this.form.datasourceDefaultPriceList.splice(index, 1);
    },
  // 资源结构add
    renderHeader(h, { column, $index }) {
      return (
        <div onClick={this.handleAdd2} class="oper-btn">
          <el-button type="primary">新增</el-button>
        </div>
      )
    },
    // 资源内容add
    renderHeader1(h, { column, $index }) {
      return (
        <div onClick={this.handleAdd1} class="oper-btn">
          <el-button type="primary">新增</el-button>
        </div>
      )
    },
    // 资源结构添加行
    handleAdd2() {
      const structForm = {
        classAlias: "未填写",
        datasourceContentList: [],
        keyword: "未填写",
        remark: "未填写",
        representation: "未填写",
        sourceId: this.a.id,
      }
      this.AllDatasourceBaseStructList.unshift(structForm);
      addDatasourceBaseStruct(structForm).then((response) => {
        console.log(response)
      })
    },
    // 资源内容添加行
    handleAdd1() {
      let  selectSQltableId1 = this.selectedValue
      if (selectSQltableId1) {
        let data = {
          columnName: "未填写",
          dataType: 5,
          name: "未填写",
          remark: "暂无",
          tableName: ""
        }
        let obj;
        this.AllDatasourceBaseStructList.forEach(function (val, i) {
          if(selectSQltableId1 == val.id){
          	obj = val;
          }
        })
        obj.datasourceContentList.unshift(data);
        addDatasourceBaseStruct(obj).then((response) => {
          console.log(response)
        })
      }
    },
    // 资源结构保存行
    handelSave(row) {
      addDatasourceBaseStruct(row).then((response) => {
        this.$modal.msgSuccess("保存成功");
      })
    },
    // 资源内容保存行
    handelSave1(row) {
      let selectSQltableId2 = this.selectedValue
      this.AllDatasourceBaseStructList.forEach((value, index) => {
			if(value.id == selectSQltableId2){
				value.datasourceContentList.forEach((val,i)=>{
					if (val.id == row.id) {
						addDatasourceBaseStruct(value).then((response) => {
              this.$modal.msgSuccess("保存成功");

            })
					}
				})
			}
		})

    },
    // 删除资源结构行
    delStructList(row) {
      const ids = row.id
      this.queryParams.sourceId = row.sourceId
      this.$modal
        .confirm('是否确认删除id为"' + ids + '"的数据项？')
        .then(function () {
          return delDatasourceBaseStruct(ids);
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          DatasourceBaseStructList(this.queryParams).then((response) => {
          const result = response.rows
          this.AllDatasourceBaseStructList = result
         })
        })
        .catch(() => {});
    },
     // 删除资源信息行
     delStructList1(row) {
       let selectSQltableId2 = this.selectedValue
       const vm = this
       this.$modal.confirm('是否确认删除?').then(function () {
         return vm.AllDatasourceBaseStructList.forEach((value, index) => {
          if(value.id == selectSQltableId2){
            value.datasourceContentList.forEach((val,i)=>{
              if (val.id == row.id) {
                value.datasourceContentList.splice(i,1);
                addDatasourceBaseStruct(value).then((response) => {
                  vm.$modal.msgSuccess("删除成功");
                })
              }
            })
          }
        })
       })

    },
  },
};
</script>
<style>
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
.el-upload-list{
  padding-left: 116px !important;
}
//目录
.el-menu-item{
  margin-left: 5px !important;
}
</style>
